﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Sale_Model;
using Sale_DAL;
using Sale_Common;
namespace Sale_Operation
{
    public class SysConfigOp
    {
        public SysConfig GetConfig(SysConfig config)
        {
            try
            {
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append(" SELECT SConf_Id,SConf_Title,SConf_Value,State,CreateTime,CreateMan FROM SysConfig WHERE SConf_Id="+config.SConf_Id);
                DataBase db = new DataBase();
                SqlHelper.FillDataset(db.Connection, CommandType.Text, sbSql.ToString(), db.Data, new string[] { "dtSysConfig"});
                if (db.Data.Tables.Count > 0)
                {
                    if (db.Data.Tables[0].Rows.Count > 0)
                    {
                        config.SConf_Title = ValueHandler.GetStringDateValue(db.Data.Tables[0].Rows[0]["SConf_Title"]);
                        config.SConf_Value = ValueHandler.GetStringDateValue(db.Data.Tables[0].Rows[0]["SConf_Value"]);
                        config.State = ValueHandler.GetIntNumberValue(db.Data.Tables[0].Rows[0]["State"]);
                    }
                }
            }
            catch (Exception ex)
            { }
            return config;
        }

        public bool Save(SysConfig SM)
        {
            bool blRes = false;
            try
            {
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append(" UPDATE SysConfig SET SConf_Value='" + ValueHandler.GetStringValue( SM.SConf_Value, ValueHandler.CharHandlerType.IsRepChar) + "' WHERE SConf_Id=" + SM.SConf_Id.ToString());
                DataBase db = new DataBase();
                SqlHelper.ExecuteNonQuery(db.Connection, CommandType.Text, sbSql.ToString());
                blRes = true;
            }
            catch(Exception ex)
            {
                LinkService.InsertLog(ESysLogType.Error, "系统配置出错！["+ex.ToString()+"]", EMenuList.系统配置);
            }
            return blRes;
        }

    }

}
